import QtQuick 1.1
//import org.kde.plasma.graphicswidgets 0.1 as PlasmaWidgets
import org.kde.plasma.core 0.1 as PlasmaCore
import "plasmapackage:/code/gmail-plasmoid.js" as GP

Item {
    id: mainItem
    
    Image {
        id: envelopeImage
        fillMode: Image.PreserveAspectFit
        smooth: false
        anchors.fill: parent
        sourceSize.height: envelopeImage.height
        sourceSize.width: envelopeImage.width
        source: "plasmapackage:/images/gmail-plasmoid.svg"

        Text {
            id: count
            color: "#2722b9"
            text: ""
            smooth: false
            font.bold: true
            anchors.horizontalCenter: parent.horizontalCenter
            anchors.verticalCenter: parent.verticalCenter
            verticalAlignment: Text.AlignVCenter
            horizontalAlignment: Text.AlignHCenter
            font.pixelSize: envelopeImage.height * 0.6
        }

        Image {
            id: overlayImage
            height: envelopeImage.height * 0.33
            width: envelopeImage.width * 0.33
            anchors.bottom: parent.bottom
            anchors.bottomMargin: 0
            anchors.right: parent.right
            anchors.rightMargin: 0
            sourceSize.height: overlayImage.height
            sourceSize.width: overlayImage.width
            source: ""
            smooth: false
            
            function setDisconnected() {
                overlayImage.source = "plasmapackage:/images/disconnected.svg"
            }
            
            function setPaused() {
                overlayImage.source = "plasmapackage:/images/paused.svg"
            }
            
            function setErrors() {
                overlayImage.source = "plasmapackage:/images/errors.svg"
            }
            
            function setClear() {
                overlayImage.source = ""
            }
        }

        MouseArea {
            anchors.fill: parent
            onClicked: {
                //plasmoid.runCommand("chromium", ["--app=https://mail.google.com"]);
                plasmoid.openUrl("https://mail.google.com");
            }
        }
        
        Timer {
            id: polltimer
            running: false
            repeat: true
            onTriggered: { GP.pollaccount() }
        }
        
    }
    
    PlasmaCore.ToolTip {
            id: toolTip
            target: mainItem
            mainText: ""
            subText: ""
    }
    
    Component.onCompleted: { GP.initialize() }
    
}
